/**
 * Created by user on 2015/9/7.
 */

var regionsService = require('../../../services/mis/master/regionsService');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');

exports.creatRegionByCity = function(req, res) {

    var input = req.body;

    regionsService.creatRegionByCityService(input, res, function (err, results) {

        if (err) {
            if(err.type == 'warning'){
                logger.warn('Warning happen when creatRegion...' + err.message);
                res.json(messageUtil.composeFailedMessage(req, err.message));
            }else {
                logger.error('Exception happen when creatRegion...' + err.message);
                res.json(messageUtil.composeFailedMessage(req, 'Exception happen when creatRegion...'));
            }
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }

    });
};


exports.regionsList = function(req, res) {

    regionsService.regionsListService(req, function (err, results) {

        if (err) {
            logger.error('Exception happen when cityList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when cityList...'));
        } else {
            var data={};
            var data = {
                count: results[0]['count'],
                totalPage: results[0]["page"],
                list: results[1]
            };
            //logger.debug('data: ');
            //logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));

        }

    });
};
